package biz.obake.team.touchprotector.features.proximity;

import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Handler;
import biz.obake.team.touchprotector.g.d;
import java.util.Map;

public class c extends biz.obake.team.touchprotector.d.b implements SensorEventListener {

    /* renamed from: d  reason: collision with root package name */
    private d f1670d = new d(this, 5, 2, "Light");
    private Handler e = new Handler();

    class a implements Runnable {
        a() {
        }

        public void run() {
            c.this.h();
        }
    }

    public class b {

        /* renamed from: a  reason: collision with root package name */
        boolean f1672a;

        /* renamed from: b  reason: collision with root package name */
        boolean f1673b;

        /* renamed from: c  reason: collision with root package name */
        boolean f1674c;

        /* renamed from: d  reason: collision with root package name */
        boolean f1675d;
        boolean e;
        boolean f;

        private b(c cVar) {
            this.f1672a = biz.obake.team.touchprotector.g.c.b("ProximityLight.Preview");
            this.f1673b = biz.obake.team.touchprotector.d.i.b.c();
            this.f1674c = !biz.obake.team.touchprotector.g.c.b("Sensors.Paused");
            this.f1675d = "Unlocked".equals(biz.obake.team.touchprotector.g.c.c("TPService.State"));
            this.e = biz.obake.team.touchprotector.g.a.g("lock_proximity");
            this.f = !"disabled".equals(biz.obake.team.touchprotector.g.a.l("proximity_light_threshold"));
        }

        /* synthetic */ b(c cVar, a aVar) {
            this(cVar);
        }
    }

    public static void d(Map<String, String> map) {
        map.put("ProximityLight.State", "Off");
        map.put("ProximityLight.Preview", "false");
        map.put("ProximityLight.Lux", "0");
    }

    public static boolean e() {
        return ((SensorManager) biz.obake.team.android.a.a().getSystemService("sensor")).getDefaultSensor(5) != null;
    }

    private String f(SensorEvent sensorEvent) {
        String l = biz.obake.team.touchprotector.g.a.l("proximity_light_threshold");
        return "disabled".equals(l) ? "Off" : ((int) sensorEvent.values[0]) >= Integer.parseInt(l) ? "Bright" : "Dark";
    }

    private void g() {
        if (!this.f1670d.g()) {
            this.f1670d.h();
        }
    }

    /* access modifiers changed from: private */
    public void h() {
        b bVar = new b(this, (a) null);
        boolean z = bVar.f1672a;
        boolean z2 = bVar.f1673b && bVar.f1674c && bVar.f1675d && bVar.e && bVar.f;
        if (z || z2) {
            g();
        } else {
            i();
        }
    }

    private void i() {
        if (this.f1670d.g()) {
            this.f1670d.j();
            biz.obake.team.touchprotector.g.c.g("ProximityLight.State", "Off");
        }
    }

    /* access modifiers changed from: protected */
    /* JADX WARNING: Can't fix incorrect switch cases order */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public void b(java.lang.String r7) {
        /*
            r6 = this;
            int r0 = r7.hashCode()
            r1 = 5
            r2 = 4
            r3 = 3
            r4 = 2
            r5 = 1
            switch(r0) {
                case -2066548004: goto L_0x003f;
                case -1182425935: goto L_0x0035;
                case -1153419070: goto L_0x002b;
                case 831789315: goto L_0x0021;
                case 1690883215: goto L_0x0017;
                case 1941313131: goto L_0x000d;
                default: goto L_0x000c;
            }
        L_0x000c:
            goto L_0x0049
        L_0x000d:
            java.lang.String r0 = "lock_proximity"
            boolean r7 = r7.equals(r0)
            if (r7 == 0) goto L_0x0049
            r7 = 4
            goto L_0x004a
        L_0x0017:
            java.lang.String r0 = "Screen.State"
            boolean r7 = r7.equals(r0)
            if (r7 == 0) goto L_0x0049
            r7 = 1
            goto L_0x004a
        L_0x0021:
            java.lang.String r0 = "Sensors.Paused"
            boolean r7 = r7.equals(r0)
            if (r7 == 0) goto L_0x0049
            r7 = 2
            goto L_0x004a
        L_0x002b:
            java.lang.String r0 = "proximity_light_threshold"
            boolean r7 = r7.equals(r0)
            if (r7 == 0) goto L_0x0049
            r7 = 5
            goto L_0x004a
        L_0x0035:
            java.lang.String r0 = "ProximityLight.Preview"
            boolean r7 = r7.equals(r0)
            if (r7 == 0) goto L_0x0049
            r7 = 0
            goto L_0x004a
        L_0x003f:
            java.lang.String r0 = "TPService.State"
            boolean r7 = r7.equals(r0)
            if (r7 == 0) goto L_0x0049
            r7 = 3
            goto L_0x004a
        L_0x0049:
            r7 = -1
        L_0x004a:
            if (r7 == 0) goto L_0x0057
            if (r7 == r5) goto L_0x0057
            if (r7 == r4) goto L_0x0057
            if (r7 == r3) goto L_0x0057
            if (r7 == r2) goto L_0x0057
            if (r7 == r1) goto L_0x0057
            goto L_0x0067
        L_0x0057:
            android.os.Handler r7 = r6.e
            r0 = 0
            r7.removeCallbacksAndMessages(r0)
            android.os.Handler r7 = r6.e
            biz.obake.team.touchprotector.features.proximity.c$a r0 = new biz.obake.team.touchprotector.features.proximity.c$a
            r0.<init>()
            r7.post(r0)
        L_0x0067:
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: biz.obake.team.touchprotector.features.proximity.c.b(java.lang.String):void");
    }

    public void onAccuracyChanged(Sensor sensor, int i) {
    }

    public void onSensorChanged(SensorEvent sensorEvent) {
        biz.obake.team.touchprotector.g.c.g("ProximityLight.Lux", Integer.toString((int) sensorEvent.values[0]));
        String f = f(sensorEvent);
        if (!f.equals(biz.obake.team.touchprotector.g.c.c("ProximityLight.State"))) {
            biz.obake.team.touchprotector.log.a b2 = biz.obake.team.touchprotector.log.a.b();
            b2.d("ProximityLight: " + f);
            biz.obake.team.touchprotector.g.c.g("ProximityLight.State", f);
        }
    }

    public void start() {
        if (e()) {
            super.start();
            h();
        }
    }

    public void stop() {
        if (e()) {
            super.stop();
            i();
        }
    }
}
